package top.soeasy.wechat.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.soeasy.common.core.domain.AjaxResult;
import top.soeasy.common.core.domain.model.MiniLoginMember;
import top.soeasy.common.utils.SecurityUtils;
import top.soeasy.common.utils.StringUtils;
import top.soeasy.wechat.service.ISysMemberService;

/**
 * 小程序端用户相关的控制器，包括发送手机验证码、手机号验证码登录、微信授权登录
 */
@RestController
@RequestMapping(value = "/mini")
public class MiniMemberController {
    @Autowired
    private ISysMemberService sysMemberService;

    /**
     * 手机号验证码登录
     * @return
     */
//    @PostMapping("login/mobile")
//    public AjaxResult mobileLogin(@RequestParam("phone") String phone,@RequestParam("code") String code) {
//        miniMemberService.loginByMobileCode(phone,code);
//        return AjaxResult.success();
//    }

    @GetMapping("/sendMobileCode")
    public AjaxResult sendMobileCode(@RequestParam("phone") String mobile) {
        String code = sysMemberService.sendPhoneCode(mobile);
        if (StringUtils.isNotEmpty(code)) {
            return AjaxResult.success("验证码发送成功！").put("verfity",code);
        } else {
            return AjaxResult.error("验证码发送失败！");
        }
    }
    @GetMapping("list")
    public AjaxResult list() {
        MiniLoginMember member = SecurityUtils.getLoginMember();
        return AjaxResult.success().put("member",member);
    }


}
